import { createRouter, createWebHashHistory } from 'vue-router'
// import HomeView0102 from '../views/example05/HomeView0102.vue'
// import ArticleList from '../views/example05/ArticleList.vue'
// import ArticleDetail from '../views/example05/ArticleDetail.vue'
// import HomeView from '../views/example05/HomeView.vue'
// import ProductView from '../views/example05/ProductView.vue'
// import DetailView from '../views/example05/DetailView.vue'
// import CommentView from '../views/example05/CommentView.vue'
import BlogHome from '../views/example05/blog/BlogHome.vue'
import BlogLogin from '../views/example05/blog/BlogLogin.vue'
import BlogArticleList from '../views/example05/blog/BlogArticleList.vue'
import BlogArticle from '../views/example05/blog/BlogArticle.vue'

const routes = [
   {
      path: '/',
      name: 'BlogHome',
      component: BlogHome
  },
   {
      path: '/login',
      name: 'BlogLogin',
      component: BlogLogin
  },
  {
    path: '/articles',
    name: 'BlogArticleList',
    component: BlogArticleList,
    // props: true
    children: [
      {
      path: ':id',
      name: 'BlogArticle',
      component: BlogArticle
      }
      ]
  },
  //   {
  //     path: '/home0102',
  //     name: 'HomeView0102',
  //     component: HomeView0102
  // },
  //     {
  //     path: '/articles',
  //     name: 'ArticleList',
  //     component: ArticleList
  // },
  //    {
  //     path: '/articles/:id',
  //     name: 'ArticleDetail',
  //     component: ArticleDetail,
  //     props: true
  // },
  // {
  //   path: '/',
  //   component:HomeView
  // },
  // {
  //   path: '/product',
  //   component: ProductView,
  //   children: [
  //     { path: 'detail', component: DetailView },
  //     { path: 'comment', component: CommentView },
  //   ]
  // }
  // {
  //   path: '/',
  //   name: 'home',
  //   component: HomeView
  // },
  // {
  //   path: '/about',
  //   name: 'about',
  //   component: () => import('../views/AboutView.vue')
  // },
  // {
  //   path: '/product',
  //   name: 'product',
  //   component: () =>  import('../views/ProductView.vue')
  // },
  // {
  //   path: '/redirect',
  //   redirect:'/'
  // }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

//全局导航守卫
router.beforeEach((to, from, next) => {
  const isAuthenticated = sessionStorage.getItem('isAuthenticated') === 'true'
  if (!isAuthenticated && to.name !== 'BlogLogin') {
    next({ name: 'BlogLogin'})
  } else {
    next()
  }
})
export default router
